<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Confirm closing window</title>
</head>
<body>
<h1>Close window now!</h1>

<script>
  window.addEventListener('beforeunload', (event) => {
    // Do not use confirm/prompt here, they will be blocked by browser!
    // See https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
    // const quit = confirm('Really quit?');
    // console.log('quit: ', quit);

    event.preventDefault();
    event.returnValue = '';
  });
</script>
</body>
</html>
